package com.yoomiito.app.present.cicle;

import com.yoomiito.app.Constant;
import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseLazyFragmentPresenter;
import com.yoomiito.app.model.cicle.CicleInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.cicle.CicleFragment;
import com.yoomiito.app.utils.NetworkUtils;
import com.yoomiito.app.utils.YMToast;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class CicleFmPresenter extends BaseLazyFragmentPresenter<CicleFragment> {

    public CicleFmPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getCicleCommunicateData(int page){
        if (NetworkUtils.checkNetPermission(getV().getContext())){
            return;
        }
        YmApi.getYmService()
                .geCicleData(page,Constant.PAGE_SIZE)
//                .compose(getV().bindToLifecycle())
                .compose(XApi.<CicleInfo>getApiTransformerData())
                .compose(XApi.<CicleInfo>getScheduler())
                .subscribe(new ApiSubscriber<CicleInfo>() {
                    @Override
                    public void onSuccess(CicleInfo data) {
                        getV().setCicleData(data);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        YMToast.showText("error");
                    }
                });
    }
}
